package com.ywl.designpattern.responsibility;

/**
 * @author yuwl
 * @description
 * @since 2024-06-28 09:59
 */
public class ChainPatternDemo {

    private static LogHandler getChainOfLoggers() {
        LogHandler errorLogger = new ErrorLogger(LogHandler.ERROR);
        LogHandler debugLogger = new DebugLogger(LogHandler.DEBUG);
        LogHandler infoLogger = new InfoLogger(LogHandler.INFO);

        errorLogger.setNextHandler(debugLogger);
        debugLogger.setNextHandler(infoLogger);

        return errorLogger;
    }

    public static void main(String[] args) {
        LogHandler loggerChain = getChainOfLoggers();

        loggerChain.logMessage(LogHandler.INFO, "This is an information");

        loggerChain.logMessage(LogHandler.DEBUG, "This is an debug level information");

        loggerChain.logMessage(LogHandler.ERROR, "This is an error level information");
    }
}
